package tgc.rj.zz.custom;

import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;



public class TimeUtils {
	/**
	 * 获取当前系统时间
	 * 
	 * @return
	 */
	public static Date getNowTime() {
		LocalDate date = LocalDate.now();
		Date date1 = Date.valueOf(date);
		return date1;
	}

	/**
	 *  
	 * 获取现在时间 
	 *    
	 *@return返回字符串格式 yyyy-MM-dd HH:mm:ss 
	 */
	public static String getStringDate() {
		java.util.Date time = new java.util.Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(time);
		return dateString;
	}
	
	
	/**
	 *  
	 * 获取现在时间 
	 *    
	 *@return返回字符串格式 yyyy-MM-dd 
	 */
	public static String getStringTime() {
		java.util.Date time = new java.util.Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(time);
		return dateString;
	}

	/**
	 * 获取当前系统时间一年后的时间
	 * 
	 * @return
	 */
	public static Date getDeadline() {
		LocalDate date = LocalDate.now();
		LocalDate date1 = date.plusYears(1);
		Date date2 = Date.valueOf(date1);
		return date2;
	}

	/***
	 * 确认授权时间
	 * 
	 * @param time 被比较时间
	 * @return
	 */

	public static boolean CompareTime(Date time) {
		LocalDate date = LocalDate.now();
		Date date1 = Date.valueOf(date);
		if (time.after(date1)) {
			return true;
		} else {

			return false;
		}
	}
	
	/***
	 * 
	 * @param time 时间String
	 * @return 星期 String
	 */
	public static String WeekDay(String time) {
		try {
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			java.util.Date date = format.parse(time);
			Instant instant = date.toInstant();
			ZoneId zoneId = ZoneId.systemDefault();
			LocalDate localDate = instant.atZone(zoneId).toLocalDate();
			DayOfWeek day = localDate.getDayOfWeek();
			String WeekDay = "";

	            switch (day)
	            {                                                                              

	                case MONDAY:

	                    WeekDay = "星期一";

	                    break;

	                case FRIDAY:

	                    WeekDay = "星期五";

	                    break;

	                case SATURDAY:

	                    WeekDay = "星期六";

	                    break;

	                case SUNDAY:

	                    WeekDay = "星期日";

	                    break;

	                case THURSDAY:

	                    WeekDay = "星期四";

	                    break;

	                case TUESDAY:

	                    WeekDay = "星期二";

	                    break;

	                case WEDNESDAY:

	                    WeekDay = "星期三";

	                    break;

	            }

	            
			return WeekDay;
		} catch (ParseException e) {
			return "报错了";
		}
	}
	
	/***
	 * 判断 为 第几学期
	 * @param profession
	 * @param schoolyear
	 * @param a 
	 * @return
	 */
/*	public static String[] Getcurrentsemester(Profession profession, Schoolyear schoolyear, String[] a) {
		//1.判断新增为 该年级的第几学期
		
		String schoolxnxq = schoolyear.getXnxq();	
		String substring = schoolxnxq.substring(0, 4);	//学年学期的年
		String sub=schoolxnxq.substring(9,13);
		Integer xn=Integer.parseInt(substring);//获取到学年起始
		
		String year = profession.getYear();
		Integer years=Integer.parseInt(year);//获取到修改的年级
		String kksjs[] = new String[2];
		if(xn-years==0) {
			if("第一学期".equals(sub)) {
				kksjs[0]= a[0];
				kksjs[1]="1";
			}else {
				kksjs[0]= a[1];
				kksjs[1]="2";
			}
		}else if(xn-years==1) {
			if("第一学期".equals(sub)) {
				kksjs[0]= a[2];
				kksjs[1]="3";
			}else {
				kksjs[0]= a[3];
				kksjs[1]="4";
			}
		}else if(xn-years==2) {
			if("第一学期".equals(sub)) {
				kksjs[0]= a[4];
				kksjs[1]="5";
			}else {
				kksjs[0]= a[5];
				kksjs[1]="6";
			}
		}
		
		return kksjs;
	}*/
}
